﻿using System;
using System.Windows.Forms;

using LazyLib.Combat;

using Frosty.Helpers;
using Frosty.Conf;

namespace Frosty.Conf
{
    public partial class Settings : Form
    {
        public Settings()
        {
            InitializeComponent();

            var specs = new[] { "Blood", "Frost", "Unholy" };

            specBox.Items.Clear();
            specBox.SelectionMode = SelectionMode.One;
            specBox.Items.Add(specs[0]);
            specBox.Items.Add(specs[1]);
            specBox.Items.Add(specs[2]);

            var presence = new[] { "Blood Presence", "Frost Presence", "Unholy Presence" };

            presenceBox.Items.Clear();
            presenceBox.SelectionMode = SelectionMode.One;
            presenceBox.Items.Add(presence[0]);
            presenceBox.Items.Add(presence[1]);
            presenceBox.Items.Add(presence[2]);

            SetControls();

        }

        public void SetControls()
        {

            specBox.SetSelected((int)ConfigValues.Spec - 1, true);

            presenceBox.SetSelected((int)ConfigValues.Presence - 1, true);

            cbk_buffPrePull.Checked = ConfigValues.BuffPrePull;
            cbk_buffInPull.Checked = ConfigValues.BuffInPull;
            cbk_buffInCombat.Checked = ConfigValues.BuffInCombat;

            ckb_darkcommand.Checked = ConfigValues.DarkCommand;
            ckb_deathgrip.Checked = ConfigValues.DeathGrip;

            ckb_unholyfrenzy.Checked = ConfigValues.UnholyFrenzy;
            ckb_hornofwinter.Checked = ConfigValues.HornofWinter;
            ckb_pillaroffrost.Checked = ConfigValues.PillarofFrost;

            ckb_ams.Checked = ConfigValues.AMS;
            ckb_boneshield.Checked = ConfigValues.BoneShield;
            ckb_ibf.Checked = ConfigValues.IBF;
            ckb_hungeringcold.Checked = ConfigValues.HungeringCold;
            ckb_vampiricblood.Checked = ConfigValues.VampiricBlood;

            ckb_icytouch.Checked = ConfigValues.IcyTouch;
            ckb_plaguestrike.Checked = ConfigValues.PlagueStrike;
            ckb_outbreak.Checked = ConfigValues.Outbreak;

            ckb_darktransformation.Checked = ConfigValues.DarkTransformation;
            ckb_deathcoil.Checked = ConfigValues.DeathCoil;
            ckb_bloodstrike.Checked = ConfigValues.BloodStrike;
            ckb_deathstrike.Checked = ConfigValues.DeathStrike;
            ckb_erw.Checked = ConfigValues.ERW;
            ckb_festeringstrike.Checked = ConfigValues.FesteringStrike;
            ckb_froststrike.Checked = ConfigValues.FrostStrike;
            ckb_heartstrike.Checked = ConfigValues.HeartStrike;
            ckb_bloodtap.Checked = ConfigValues.BloodTap;
            ckb_howlingblast.Checked = ConfigValues.HowlingBlast;
            ckb_mindfreeze.Checked = ConfigValues.MindFreeze;
            ckb_obliterate.Checked = ConfigValues.Obliterate;
            ckb_pestilence.Checked = ConfigValues.Pestilence;
            ckb_raisedead.Checked = ConfigValues.RaiseDead;
            ckb_runestrike.Checked = ConfigValues.RuneStrike;
            ckb_runetap.Checked = ConfigValues.RuneTap;
            ckb_scourgestrike.Checked = ConfigValues.ScourgeStrike;
            ckb_strangulate.Checked = ConfigValues.Strangulate;
            ckb_summongargoyle.Checked = ConfigValues.SummonGargoyle;
            ckb_deathanddecay.Checked = ConfigValues.DeathAndDecay;

            cbk_glyph_howlingblast.Checked = ConfigValues.HowlingBlastGlyph;

            bar_dsheal.Value = ConfigValues.DeathStrikePercent;
            bar_runetap.Value = ConfigValues.RuneTapPercent;
            bar_ibf.Value = ConfigValues.IBFPercent;

            txt_deathStrikePercent.Text = bar_dsheal.Value.ToString();
            txt_runeTapPercent.Text = bar_runetap.Value.ToString();
            txt_ibfpercent.Text = bar_ibf.Value.ToString();
        }

        /// <summary>
        ///   Sets the values.
        /// </summary>
        public void SetValues()
        {
            ConfigValues.Spec = (Spec)specBox.SelectedIndex + 1;

            ConfigValues.Presence = (Presence)presenceBox.SelectedIndex + 1;

            ConfigValues.BuffPrePull = cbk_buffPrePull.Checked;
            ConfigValues.BuffInPull = cbk_buffInPull.Checked;
            ConfigValues.BuffInCombat = cbk_buffInCombat.Checked;

            ConfigValues.DarkCommand = ckb_darkcommand.Checked;
            ConfigValues.DeathGrip = ckb_deathgrip.Checked;

            ConfigValues.AMS = ckb_ams.Checked;
            ConfigValues.IBF = ckb_ibf.Checked;
            ConfigValues.HungeringCold = ckb_hungeringcold.Checked;
            ConfigValues.BoneShield = ckb_boneshield.Checked;
            ConfigValues.VampiricBlood = ckb_vampiricblood.Checked;

            ConfigValues.Outbreak = ckb_outbreak.Checked;
            ConfigValues.IcyTouch = ckb_icytouch.Checked;
            ConfigValues.PlagueStrike = ckb_plaguestrike.Checked;

            ConfigValues.HornofWinter = ckb_hornofwinter.Checked;
            ConfigValues.UnholyFrenzy = ckb_unholyfrenzy.Checked;
            ConfigValues.PillarofFrost = ckb_pillaroffrost.Checked;

            ConfigValues.HowlingBlast = ckb_howlingblast.Checked;
            ConfigValues.BloodStrike = ckb_bloodstrike.Checked;
            ConfigValues.BloodTap = ckb_bloodtap.Checked;
            ConfigValues.DarkTransformation = ckb_darktransformation.Checked;
            ConfigValues.DeathCoil = ckb_deathcoil.Checked;
            ConfigValues.DeathStrike = ckb_deathstrike.Checked;
            ConfigValues.ERW = ckb_erw.Checked;
            ConfigValues.FesteringStrike = ckb_festeringstrike.Checked;
            ConfigValues.FrostStrike = ckb_froststrike.Checked;
            ConfigValues.HeartStrike = ckb_heartstrike.Checked;
            ConfigValues.MindFreeze = ckb_mindfreeze.Checked;
            ConfigValues.Obliterate = ckb_obliterate.Checked;
            ConfigValues.Pestilence = ckb_pestilence.Checked;
            ConfigValues.RaiseDead = ckb_raisedead.Checked;
            ConfigValues.RuneStrike = ckb_runestrike.Checked;
            ConfigValues.RuneTap = ckb_runetap.Checked;
            ConfigValues.ScourgeStrike = ckb_scourgestrike.Checked;
            ConfigValues.Strangulate = ckb_strangulate.Checked;
            ConfigValues.SummonGargoyle = ckb_summongargoyle.Checked;
            
            ConfigValues.DeathAndDecay = ckb_deathanddecay.Checked;

            ConfigValues.HowlingBlastGlyph = cbk_glyph_howlingblast.Checked;

            ConfigValues.DeathStrikePercent = bar_dsheal.Value;
            ConfigValues.RuneTapPercent = bar_runetap.Value;
            ConfigValues.IBFPercent = bar_ibf.Value;
        }

        private void bar_dsheal_Scroll(object sender, EventArgs e)
        {
            txt_deathStrikePercent.Text = bar_dsheal.Value.ToString();
        }

        private void bar_runetap_Scroll(object sender, EventArgs e)
        {
            txt_runeTapPercent.Text = bar_runetap.Value.ToString();
        }

        private void bar_ibf_Scroll(object sender, EventArgs e)
        {
            txt_ibfpercent.Text = bar_ibf.Value.ToString();
        }

        private void Settings_Load(object sender, EventArgs e)
        {

        }

        private void btn_save_Click(object sender, EventArgs e)
        {
            SetValues();
            Ini.SaveValues();

            LogType spec = LogType.Warning;
            switch (ConfigValues.Spec)
            {
                case Spec.Blood:
                    spec = LogType.Error;
                    break;
                case Spec.Frost:
                    spec = LogType.Normal;
                    break;
                case Spec.Unholy:
                    spec = LogType.Good;
                    break;
            }

            LogType presence = LogType.Warning;
            switch (ConfigValues.Presence)
            {
                case Presence.BloodPresence:
                    presence = LogType.Error;
                    break;
                case Presence.FrostPresence:
                    presence = LogType.Normal;
                    break;
                case Presence.UnholyPresence:
                    presence = LogType.Good;
                    break;
            }

            CombatEngine.Log("Selected Talent Spec: " + ConfigValues.Spec, spec);
            CombatEngine.Log("Selected Presence: " + ConfigValues.Presence, presence);

            Form.ActiveForm.Close();
        }

        private void nameLabel_Click(object sender, EventArgs e)
        {

        }
    }
}
